package com.snowRemovingUser.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.snowRemovingUser.domain.TAccessStatistics;
import com.snowRemovingUser.service.ITAccessStatisticsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 访问统计Controller
 * 
 * @author liguang
 * @date 2023-04-13
 */
@RestController
@RequestMapping("/snowRemoving/statistics")
public class TAccessStatisticsController extends BaseController
{
    @Autowired
    private ITAccessStatisticsService tAccessStatisticsService;

    /**
     * 查询访问统计列表
     */
    @PreAuthorize("@ss.hasPermi('snowRemoving:statistics:list')")
    @GetMapping("/list")
    public TableDataInfo list(TAccessStatistics tAccessStatistics)
    {
        startPage();
        List<TAccessStatistics> list = tAccessStatisticsService.selectTAccessStatisticsList(tAccessStatistics);
        return getDataTable(list);
    }

    /**
     * 导出访问统计列表
     */
    @PreAuthorize("@ss.hasPermi('snowRemoving:statistics:export')")
    @Log(title = "访问统计", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TAccessStatistics tAccessStatistics)
    {
        List<TAccessStatistics> list = tAccessStatisticsService.selectTAccessStatisticsList(tAccessStatistics);
        ExcelUtil<TAccessStatistics> util = new ExcelUtil<TAccessStatistics>(TAccessStatistics.class);
        util.exportExcel(response, list, "访问统计数据");
    }

    /**
     * 获取访问统计详细信息
     */
    @PreAuthorize("@ss.hasPermi('snowRemoving:statistics:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(tAccessStatisticsService.selectTAccessStatisticsById(id));
    }

    /**
     * 新增访问统计
     */
    @PreAuthorize("@ss.hasPermi('snowRemoving:statistics:add')")
    @Log(title = "访问统计", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TAccessStatistics tAccessStatistics)
    {
        return toAjax(tAccessStatisticsService.insertTAccessStatistics(tAccessStatistics));
    }

    /**
     * 修改访问统计
     */
    @PreAuthorize("@ss.hasPermi('snowRemoving:statistics:edit')")
    @Log(title = "访问统计", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TAccessStatistics tAccessStatistics)
    {
        return toAjax(tAccessStatisticsService.updateTAccessStatistics(tAccessStatistics));
    }

    /**
     * 删除访问统计
     */
    @PreAuthorize("@ss.hasPermi('snowRemoving:statistics:remove')")
    @Log(title = "访问统计", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tAccessStatisticsService.deleteTAccessStatisticsByIds(ids));
    }
}
